shell.set_verbose(options.flag_verbose);
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
- let env = if options.flag_example.is_some() {
- "test"
- } else if options.flag_release {
- "release"
- } else {
- "compile"
+ let env = match (options.flag_release, options.flag_example.is_some()) {
+ (true, true) => "bench",
+ (true, false) => "release",
+ (false, true) => "test",
+ (false, false) => "compile"
};
let mut compile_opts = ops::CompileOptions {
}
}
+ pub fn default_example() -> Profile {
+ Profile {
+ test: false,
+ .. Profile::default_test()
+ }
+ }
+
pub fn default_bench() -> Profile {
Profile {
env: "bench".to_string(),
}
}
+ pub fn default_example_release() -> Profile {
+ Profile {
+ test: false,
+ .. Profile::default_bench()
+ }
+ }
+
pub fn default_release() -> Profile {
Profile {
env: "release".to_string(),
let dst = manifest_path.dir_path().join("target");
let dst = match options.target {
Some(target) => dst.join(target),
- None => if bin.is_example() { dst.join("examples") } else { dst },
+ None => dst,
};
- let exe = match bin.get_profile().get_dest() {
- Some(s) => dst.join(s).join(bin.get_name()),
- None => dst.join(bin.get_name()),
+ let exe = match (bin.get_profile().get_dest(), bin.is_example()) {
+ (Some(s), true) => dst.join(s).join("examples").join(bin.get_name()),
+ (Some(s), false) => dst.join(s).join(bin.get_name()),
+ (None, true) => dst.join("examples").join(bin.get_name()),
+ (None, false) => dst.join(bin.get_name()),
};
let exe = match exe.path_relative_from(&try!(os::getcwd())) {
Some(path) => path,
use std::io::USER_RWX;
use std::io::fs::{self, PathExtensions};
use std::sync::Arc;
+use std::path;
use core::{SourceMap, Package, PackageId, PackageSet, Target, Resolve};
use util::{self, CargoResult, human, caused_human};
v.push_all(target.get_name().as_bytes());
v.push(b'=');
v.push_all(layout.root().as_vec());
- v.push(b'/');
+ v.push(path::SEP_BYTE);
v.push_all(filename.as_bytes());
cmd = cmd.arg("--extern").arg(v.as_slice());
}
for ex in examples.iter() {
let path = ex.path.clone().unwrap_or_else(|| PathValue::String(default(ex)));
- let profile = Profile::default_test().test(false);
- let profile = merge(profile, &profiles.test);
+ let profile = merge(Profile::default_example(), &profiles.test);
+ let profile_release = merge(Profile::default_example_release(), &profiles.release);
dst.push(Target::example_target(ex.name.as_slice(),
&path.to_path(),
&profile));
+ dst.push(Target::example_target(ex.name.as_slice(),
+ &path.to_path(),
+ &profile_release));
}
}
--emit=dep-info,link \
-L dependency={dir}{sep}target{sep}release \
-L dependency={dir}{sep}target{sep}release{sep}deps \
- --extern foo={dir}{sep}target{sep}release{sep}deps/\
+ --extern foo={dir}{sep}target{sep}release{sep}deps{sep}\
{prefix}foo-[..]{suffix} \
- --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
+ --extern foo={dir}{sep}target{sep}release{sep}deps{sep}libfoo-[..].rlib`
",
running = RUNNING,
compiling = COMPILING,
--emit=dep-info,link \
-L dependency={dir}{sep}target{sep}release \
-L dependency={dir}{sep}target{sep}release{sep}deps \
- --extern foo={dir}{sep}target{sep}release{sep}deps/\
+ --extern foo={dir}{sep}target{sep}release{sep}deps{sep}\
{prefix}foo-[..]{suffix} \
- --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
+ --extern foo={dir}{sep}target{sep}release{sep}deps{sep}libfoo-[..].rlib`
",
running = RUNNING,
compiling = COMPILING,
sep = path::SEP).as_slice()));
});
+test!(example_with_release_flag {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies.bar]
+ version = "*"
+ path = "bar"
+ "#)
+ .file("examples/a.rs", r#"
+ extern crate bar;
+
+ fn main() {
+ if cfg!(ndebug) {
+ println!("fast1")
+ } else {
+ println!("slow1")
+ }
+ bar::baz();
+ }
+ "#)
+ .file("bar/Cargo.toml", r#"
+ [project]
+ name = "bar"
+ version = "0.0.1"
+ authors = []
+
+ [lib]
+ name = "bar"
+ "#)
+ .file("bar/src/bar.rs", r#"
+ pub fn baz() {
+ if cfg!(ndebug) {
+ println!("fast2")
+ } else {
+ println!("slow2")
+ }
+ }
+ "#);
+
+ assert_that(p.cargo_process("run").arg("-v").arg("--release").arg("--example").arg("a"),
+ execs().with_status(0).with_stdout(format!("\
+{compiling} bar v0.0.1 ({url})
+{running} `rustc src{sep}bar.rs --crate-name bar --crate-type lib \
+ -C opt-level=3 \
+ --cfg ndebug \
+ -C metadata=[..] \
+ -C extra-filename=[..] \
+ --out-dir {dir}{sep}target{sep}release{sep}deps \
+ --emit=dep-info,link \
+ -L dependency={dir}{sep}target{sep}release{sep}deps \
+ -L dependency={dir}{sep}target{sep}release{sep}deps`
+{compiling} foo v0.0.1 ({url})
+{running} `rustc {dir}{sep}examples{sep}a.rs --crate-name a --crate-type bin \
+ -C opt-level=3 \
+ --cfg ndebug \
+ --out-dir {dir}{sep}target{sep}release{sep}examples \
+ --emit=dep-info,link \
+ -L dependency={dir}{sep}target{sep}release \
+ -L dependency={dir}{sep}target{sep}release{sep}deps \
+ --extern bar={dir}{sep}target{sep}release{sep}deps{sep}libbar-[..].rlib`
+{running} `target{sep}release{sep}examples{sep}a`
+fast1
+fast2
+",
+ compiling = COMPILING,
+ running = RUNNING,
+ dir = p.root().display(),
+ url = path2url(p.root()),
+ sep = path::SEP).as_slice()));
+
+ assert_that(p.process(cargo_dir().join("cargo")).arg("run").arg("-v").arg("--example").arg("a"),
+ execs().with_status(0).with_stdout(format!("\
+{compiling} bar v0.0.1 ({url})
+{running} `rustc src{sep}bar.rs --crate-name bar --crate-type lib \
+ -g \
+ -C metadata=[..] \
+ -C extra-filename=[..] \
+ --out-dir {dir}{sep}target{sep}deps \
+ --emit=dep-info,link \
+ -L dependency={dir}{sep}target{sep}deps \
+ -L dependency={dir}{sep}target{sep}deps`
+{compiling} foo v0.0.1 ({url})
+{running} `rustc {dir}{sep}examples{sep}a.rs --crate-name a --crate-type bin \
+ -g \
+ --out-dir {dir}{sep}target{sep}examples \
+ --emit=dep-info,link \
+ -L dependency={dir}{sep}target \
+ -L dependency={dir}{sep}target{sep}deps \
+ --extern bar={dir}{sep}target{sep}deps{sep}libbar-[..].rlib`
+{running} `target{sep}examples{sep}a`
+slow1
+slow2
+",
+ compiling = COMPILING,
+ running = RUNNING,
+ dir = p.root().display(),
+ url = path2url(p.root()),
+ sep = path::SEP).as_slice()));
+});
+
test!(run_dylib_dep {
let p = project("foo")
.file("Cargo.toml", r#"